package com.hyc.myvideo.ui.fragment.homefargment;


import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hyc.myvideo.R;
import com.hyc.myvideo.share.shareUtils;
import com.hyc.myvideo.ui.activity.home.TrainingActivity;
import com.hyc.myvideo.ui.activity.my.ApplyActivity;
import com.hyc.myvideo.ui.activity.my.AttentionActivity;
import com.hyc.myvideo.ui.activity.my.BalanceActivity;
import com.hyc.myvideo.ui.activity.my.CommentActivity;
import com.hyc.myvideo.ui.activity.my.CommissionActivity;
import com.hyc.myvideo.ui.activity.my.CouponActivity;
import com.hyc.myvideo.ui.activity.my.CourseActivity;
import com.hyc.myvideo.ui.activity.my.DownloadActivity;
import com.hyc.myvideo.ui.activity.my.EditActivity;
import com.hyc.myvideo.ui.activity.my.LoginActivity;
import com.hyc.myvideo.ui.activity.my.PurchasingActivity;
import com.hyc.myvideo.ui.activity.my.RechargeActivity;
import com.hyc.myvideo.ui.activity.my.SiteActivity;
import com.hyc.myvideo.ui.activity.my.StatisticsActivity;
import com.hyc.myvideo.ui.activity.my.SuggestActivity;
import com.hyc.myvideo.ui.base.BaseFragment;
import com.hyc.myvideo.utils.imguitl.ImgUitl;
import com.hyc.utils.StringUtils;
import com.umeng.socialize.ShareContent;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 我的
 *
 * @author gyb
 * @version 1.0
 * @created 2017/06/16
 */
public class MyFragment extends BaseFragment {
    /**
     * 标题
     */
    @BindView(R.id.head_center_title)
    TextView textTitle;
    /**
     * 设置
     */
    @BindView(R.id.head_right_title)
    TextView textSite;
    /**
     * 头像
     */
    @BindView(R.id.img_head_id)
    ImageView imageViewHead;
    /**
     * 名称
     */
    @BindView(R.id.t_name_id)
    TextView textViewName;
    /**
     * 标记
     */
    @BindView(R.id.t_vip_mark)
    TextView textViewMark;

    /**
     * 讲师展示
     */
    @BindView(R.id.r_layout_lecturer)
    LinearLayout linearLayoutView;
    /**
     * 讲师展示统计
     */
    @BindView(R.id.r_layout_lecturer_statistics)
    LinearLayout layoutStatisticsView;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_my;
    }

    protected void initView() {
        setTextTitle();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onNexts(String result, String method) {
    }

    @Override
    protected void onError() {

    }

    @Override
    public void onResume() {
        super.onResume();
        showUserIofo();
    }


    /***
     * 展示会员信息
     */
    private void showUserIofo() {
        //昵称
        String nickname = userInfo.getUser_nickname();
        if (StringUtils.isEmpty(nickname)) {
            textViewName.setText("登录/注册");
        } else {
            textViewName.setText(nickname);
        }
        int state = userInfo.getUser_vip_state();
        if (state > 0) {
            textViewMark.setText(userInfo.getVip_name());
            textViewMark.setVisibility(View.VISIBLE);
        } else {
            textViewMark.setVisibility(View.GONE);
        }
        //展示头像
        String url = userInfo.getUser_face();
        ImgUitl.setLocalRoundImg(url, imageViewHead, R.dimen.app_img_hw70);

        String type = userInfo.getUser_type();
        if ("2".equalsIgnoreCase(type)) {
            linearLayoutView.setVisibility(View.VISIBLE);
            layoutStatisticsView.setVisibility(View.VISIBLE);
        } else {
            linearLayoutView.setVisibility(View.GONE);
            layoutStatisticsView.setVisibility(View.GONE);
        }
    }

    private void setTextTitle() {
        if (textTitle != null) {
            textTitle.setVisibility(View.VISIBLE);
            textTitle.setText(R.string.home_title_my);
        }
        if (textSite != null) {
            textSite.setVisibility(View.VISIBLE);
            textSite.setText(R.string.home_title_site);
        }
    }

    @OnClick({
            R.id.r_edit_log, R.id.t_home_id, R.id.t_recharge_id, R.id.t_balance_id,
            R.id.r_download_id, R.id.r_purchasing_id, R.id.r_names_id, R.id.r_comment_id,
            R.id.r_attention_id, R.id.r_coupon_id, R.id.r_course_id, R.id.r_commission_id,
            R.id.r_commission_statistics_id, R.id.r_share_id, R.id.r_suggestion_id, R.id.head_right_title
    })
    public void onClick(View view) {
        switch (view.getId()) {
            /**编辑*/
            case R.id.r_edit_log:
                if(LoginActivity.checkLogin(getActivity(), new LoginActivity.LoginCallback(){
                    @Override
                    public void onLogin(){}
                })){
                    startActivity(new Intent(appContext, EditActivity.class));
                }
                break;
            /**我的主页*/
            case R.id.t_home_id:
                startActivity(TrainingActivity.class, "");
                break;
            /**充值会员*/
            case R.id.t_recharge_id:
                startActivity(RechargeActivity.class, "");
                break;
            /**账户余额*/
            case R.id.t_balance_id:
                startActivity(BalanceActivity.class, "");
                break;
            /**我的下载*/
            case R.id.r_download_id:
                startActivity(DownloadActivity.class, getStr(R.string.huc_my_text_download));
                break;
            /**我的购买*/
            case R.id.r_purchasing_id:
                startActivity(PurchasingActivity.class, getStr(R.string.huc_my_text_buy));
                break;
            /**我的报名*/
            case R.id.r_names_id:
                startActivity(ApplyActivity.class, getStr(R.string.huc_my_text_apply));
                break;
            /**我的评论*/
            case R.id.r_comment_id:
                startActivity(CommentActivity.class, getStr(R.string.huc_my_text_comment));
                break;
            /**我的关注*/
            case R.id.r_attention_id:
                startActivity(AttentionActivity.class, getStr(R.string.huc_my_text_attention));
                break;
            /**我的优惠券*/
            case R.id.r_coupon_id:
                startActivity(CouponActivity.class, getStr(R.string.huc_my_text_coupon));
                break;
            /**我的课程*/
            case R.id.r_course_id:
                startActivity(CourseActivity.class, getStr(R.string.huc_my_text_course));
                break;
            /**我的佣金*/
            case R.id.r_commission_id:
                startActivity(CommissionActivity.class, getStr(R.string.huc_my_text_commission));
                break;
            /**提成统计*/
            case R.id.r_commission_statistics_id:
                startActivity(StatisticsActivity.class, getStr(R.string.huc_my_text_statistics));
                break;
            /**设置*/
            case R.id.head_right_title:
                startActivity(new Intent(getActivity(), SiteActivity.class));
                break;
            /**分享*/
            case R.id.r_share_id:
                new shareUtils(getActivity(), new ShareContent());
                break;
            /**反馈建议*/
            case R.id.r_suggestion_id:
                startActivity(new Intent(getActivity(), SuggestActivity.class));
                break;
        }
    }

    /***
     * 验证登陆后跳转
     * @param cls
     * @param value
     */
    private void startActivity(final Class<?> cls, final String value) {
        LoginActivity.checkLogin(getActivity(), new LoginActivity.LoginCallback() {
            @Override
            public void onLogin() {
                startActivity(new Intent(getActivity(), cls).putExtra("title", value));
            }
        });
    }

}
